<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="google-site-verification" content="xBT4GhYoi5qRD5tr338pgPM5OWHHIDR6mNg1a3euekI" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="keyword"  content="">
    <link rel="shortcut icon" href="/img/ironman-draw.png">
    <!-- Place this tag in your head or just before your close body tag. -->
    <script async defer src="https://buttons.github.io/buttons.js"></script>
    <title>
        
          Mac下使用Vagrant+VirtualBox快速搭建Centos/7虚拟机 - 吃素的左撇子 | Blog
        
    </title>

    <link rel="canonical" href="http://www.wangxiaohuan.com/虚拟机/2019-01-07/">

    <!-- Bootstrap Core CSS -->
    
<link rel="stylesheet" href="/css/bootstrap.min.css">


    <!-- Custom CSS --> 
    
<link rel="stylesheet" href="/css/beantech.min.css">


    
<link rel="stylesheet" href="/css/donate.css">

    
    <!-- Pygments Highlight CSS -->
    
<link rel="stylesheet" href="/css/highlight.css">


    
<link rel="stylesheet" href="/css/widget.css">


    
<link rel="stylesheet" href="/css/rocket.css">


    
<link rel="stylesheet" href="/css/signature.css">


    
<link rel="stylesheet" href="/css/toc.css">


    <!-- Custom Fonts -->
    <!-- <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css"> -->
    <!-- Hux change font-awesome CDN to qiniu -->
    <link href="https://cdn.staticfile.org/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">


    <!-- Hux Delete, sad but pending in China
    <link href='http://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/
    css'>
    -->


    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- ga & ba script hoook -->
    <script></script>
<meta name="generator" content="Hexo 4.2.1"></head>


<!-- hack iOS CSS :active style -->
<body ontouchstart="">
	<!-- Modified by Yu-Hsuan Yen -->
<!-- Post Header -->
<style type="text/css">
    header.intro-header{
        
            background-image: url('http://image.wangxiaohuan.com/blog/image/202109091152630.png')
            /*post*/
        
    }
    
</style>

<header class="intro-header" >
    <!-- Signature -->
    <div id="signature">
        <div class="container">
            <div class="row">
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                
                    <div class="post-heading">
                        <div class="tags">
                            
                              <a class="tag" href="/tags/#工具" title="工具">工具</a>
                            
                        </div>
                        <h1>Mac下使用Vagrant+VirtualBox快速搭建Centos/7虚拟机</h1>
                        <h2 class="subheading"></h2>
                        <span class="meta">
                            Posted by 吃素的左撇子 on
                            2019-01-07
                        </span>
                    </div>
                


                </div>
            </div>
        </div>
    </div>
</header>

	
    <!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">吃素的左撇子</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <!-- Known Issue, found by Hux:
            <nav>'s height woule be hold on by its content.
            so, when navbar scale out, the <nav> will cover tags.
            also mask any touch event of tags, unfortunately.
        -->
        <div id="huxblog_navbar">
            <div class="navbar-collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="/">Home</a>
                    </li>

                    

                        
                    

                        
                        <li>
                            <a href="/about/">About Me</a>
                        </li>
                        
                    

                        
                        <li>
                            <a href="/archive/">Archive</a>
                        </li>
                        
                    

                        
                        <li>
                            <a href="/tags/">Tags</a>
                        </li>
                        
                    
                    
                </ul>
            </div>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>
<script>
    // Drop Bootstarp low-performance Navbar
    // Use customize navbar with high-quality material design animation
    // in high-perf jank-free CSS3 implementation
    var $body   = document.body;
    var $toggle = document.querySelector('.navbar-toggle');
    var $navbar = document.querySelector('#huxblog_navbar');
    var $collapse = document.querySelector('.navbar-collapse');

    $toggle.addEventListener('click', handleMagic)
    function handleMagic(e){
        if ($navbar.className.indexOf('in') > 0) {
        // CLOSE
            $navbar.className = " ";
            // wait until animation end.
            setTimeout(function(){
                // prevent frequently toggle
                if($navbar.className.indexOf('in') < 0) {
                    $collapse.style.height = "0px"
                }
            },400)
        }else{
        // OPEN
            $collapse.style.height = "auto"
            $navbar.className += " in";
        }
    }
</script>


    <!-- Main Content -->
    <!-- Modify by Yu-Hsuan Yen -->

<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">

            <!-- Post Container -->
            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                post-container">

                <h2 id="前言">前言</h2>
<p>日常开发过程中，为了保证开发环境的统一并且又不想污染我们本机的环境，通常我们有 2 种方式可以做到，一种是状态火热的docker虚拟化技术，另一种就是我们经久不衰的虚拟机了。本文介绍在 Mac 下使用 Vagrant 快速搭建Centos7 虚拟机。</p>
<hr>
<h2 id="1-什么是-vagrant">1. 什么是 Vagrant</h2>
<h3 id="11-vagrant-简介">1.1. Vagrant 简介</h3>
<p>什么是 Vagrant，要回答这个问题，最好的答案应该来自官网(<a href="https://www.vagrantup.com/intro/index.html" target="_blank" rel="noopener">https://www.vagrantup.com/intro/index.html</a>)</p>
<blockquote>
<p>Vagrant is a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity, and makes the “works on my machine” excuse a relic of the past.</p>
</blockquote>
<p>翻译：Vagrant 是一个在单个工作流中实现构建和管理虚拟机环境的工具。通过一种简单易用的工作流并专注于自动化，Vagrant 减少了开发环境的配置时间，提高了生产效率，也正因为 Vagrant 的存在，使得『这个在我的电脑可以运行』这种借口成为过去。</p>
<p>官网的简介，我们简单的总结一下：<code>Vagrant 是一个可以快速构建并管理虚拟机的工具</code>。</p>
<h3 id="12-vagrant-优势">1.2. Vagrant 优势</h3>
<ol>
<li>配置简单，避免相同环境重复配置，仅需共享一个 <code>Vagrantfile</code> 即可快速搭建一个相同配置的虚拟机。</li>
<li>一处配置，多端运行，不受系统环境影响，<code>Linux / Mac OS X / Windows</code> 启用命令一致。</li>
<li>安装简单，卸载干净。安装虚拟机，只会在当前 <code>Vagrantfile</code> 目录生成少数的缓存文件，卸载时可以卸载的干干净净，丝毫不污染宿主机环境。</li>
<li>支持多种 <code>provider</code>，便于用户自行选择 provider 去挂载虚拟机，包括：<code>VirtualBox</code>，<code>VMware</code>，<code>AWS</code>，<code>Docker</code> 等。</li>
</ol>
<hr>
<h2 id="2-安装-vagrant">2. 安装 Vagrant</h2>
<h3 id="21-环境准备">2.1. 环境准备</h3>
<p>安装 provider，主要用于挂载虚拟机。本文将采用开源免费的 <code>VirtualBox</code> 作为 Vagrant 的 provider 来挂载我们的虚拟机。<code>VirtualBox</code> 是一款开源免费的虚拟机软件，相比 <code>VMware</code> 体系的软件来说，更加 <s>小巧</s>（主要是 <strong>免费</strong>）。</p>
<blockquote>
<p>下载地址：<a href="https://www.virtualbox.org/wiki/Downloads" target="_blank" rel="noopener">https://www.virtualbox.org/wiki/Downloads</a></p>
</blockquote>
<p>安装方式是傻瓜式安装，只需要选择好对应系统的版本，下一步操作即可。</p>
<h3 id="22-安装-vagrant">2.2. 安装 Vagrant</h3>
<p>主角登场，接下来我们来安装 <code>Vagrant</code>。</p>
<blockquote>
<p>下载地址：<a href="https://www.vagrantup.com/downloads.html" target="_blank" rel="noopener">https://www.vagrantup.com/downloads.html</a></p>
</blockquote>
<p>安装方式和 VirtualBox 一样，同样是傻瓜式安装，只需要选择好对应系统的版本，下一步操作即可。</p>
<p>安装完成之后，前往 Terminal 执行命令验证是否安装成功：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ vagrant version</span><br><span class="line">Installed Version: 2.2.18</span><br><span class="line">Latest Version: 2.2.18</span><br><span class="line"></span><br><span class="line">You&#39;re running an up-to-date version of Vagrant!</span><br></pre></td></tr></table></figure>
<hr>
<h2 id="3-vagrant-命令">3. Vagrant 命令</h2>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">vagrant init &lt;名称&gt;   # 初始化box的操作</span><br><span class="line">vagrant box add &lt;虚拟机名&gt; &lt;box文件名&gt;   # 添加box的操作</span><br><span class="line">vagrant up   # 启动虚拟机的操作</span><br><span class="line">vagrant ssh &lt;hostname&gt;   # 登录拟机的操作，也可以指定hostname登陆</span><br><span class="line">vagrant box list   # 显示当前已经添加的box列表</span><br><span class="line">vagrant box remove 名称   # 删除相应的box  </span><br><span class="line">vagrant destroy   # 停止当前正在运行的虚拟机并销毁所有创建的资源</span><br><span class="line">vagrant halt   # 关机</span><br><span class="line">vagrant status &lt;hostname&gt;   # 获取当前虚拟机的状态，也可以查看指定hostname</span><br><span class="line">vagrant suspend   # 挂起当前的虚拟机</span><br><span class="line">vagrant resume   # 恢复前面被挂起的状态</span><br><span class="line">vagrant reload   # 重新启动虚拟机，主要用于重新载入配置文件</span><br><span class="line">vagrant global-status   # 查看所有虚拟机的ID号</span><br><span class="line">vagrant plugin   # 用于安装卸载插件</span><br><span class="line">vagrant ssh-config   # 输出用于ssh连接的一些信息</span><br><span class="line">vagrant package   # 打包命令，可以把当前的运行的虚拟机环境进行打包</span><br><span class="line">vagrant ssh-config   # 查看ssh登录信息，可以把这些信息 保存到.ssh文件下config中，先用vagrant ssh 登录，然后把宿主机的ssh公钥保存到虚拟机的authorized_keys文件里，然后在宿主机ssh &lt;名称&gt;就可以免密码登录</span><br></pre></td></tr></table></figure>
<hr>
<h2 id="4-vagrant-实战">4. Vagrant 实战</h2>
<blockquote>
<p>本小节我们完成一个实战，使用 Vagrant 安装 centos7。</p>
</blockquote>
<h3 id="41-寻找box">4.1. 寻找box</h3>
<p>box 就是我们系统的初始化镜像，我们可以在 <a href="http://www.vagrantbox.es/" target="_blank" rel="noopener">http://www.vagrantbox.es/</a> 找到我们需要的系统镜像</p>
<blockquote>
<p>建议大家去给这个仓库点个 Star，方便好用的东西永远值得表扬! 附上仓库链接：<a href="https://github.com/garethr/vagrantboxes-heroku" target="_blank" rel="noopener">https://github.com/garethr/vagrantboxes-heroku</a> 。</p>
</blockquote>
<p>[<img src="http://image.wangxiaohuan.com/blog/image/202109091229243.png" alt="vagrantbox-es"></p>
<p>理论上这里能搜到的 box，都可以在下面的初始化中直接使用 <code>init</code> 命令直接初始化。（但是国内的网络会导致经常失败。）</p>
<p>因此我们可以拷贝上面的 box 链接，先单独下载，再进行安装。</p>
<p>假设我们的 box 下载地址为：<code>/Users/wangxiaohuan/Downloads/vagrant-images/CentOS-7-x86_64-Vagrant-1803_01.VirtualBox.box</code></p>
<p>打开 Terminal，输入如下命令：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ vagrant box add centos&#x2F;7 &#x2F;Users&#x2F;wangxiaohuan&#x2F;Downloads&#x2F;vagrant-images&#x2F;CentOS-7-x86_64-Vagrant-1803_01.VirtualBox.box</span><br><span class="line">&#x3D;&#x3D;&gt; box: Box file was not detected as metadata. Adding it directly...</span><br><span class="line">&#x3D;&#x3D;&gt; box: Adding box &#39;centos&#x2F;7&#39; (v0) for provider:</span><br><span class="line">    box: Unpacking necessary files from: file:&#x2F;&#x2F;&#x2F;Users&#x2F;yangkai.shen&#x2F;Downloads&#x2F;vagrant-images&#x2F;CentOS-7-x86_64-Vagrant-1803_01.VirtualBox.box</span><br><span class="line">&#x3D;&#x3D;&gt; box: Successfully added box &#39;centos&#x2F;7&#39; (v0) for &#39;virtualbox&#39;!</span><br></pre></td></tr></table></figure>
<p>这样，我们就可以使用我们添加的 box 进行初始化了。</p>
<h3 id="42-初始化">4.2. 初始化</h3>
<p>我们创建一个目录 <code>centos7</code>，然后在 Terminal 中进入该目录，然后执行初始化命令。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ vagrant init centos&#x2F;7</span><br><span class="line">A &#96;Vagrantfile&#96; has been placed in this directory. You are now</span><br><span class="line">ready to &#96;vagrant up&#96; your first virtual environment! Please read</span><br><span class="line">the comments in the Vagrantfile as well as documentation on</span><br><span class="line">&#96;vagrantup.com&#96; for more information on using Vagrant.</span><br></pre></td></tr></table></figure>
<p>此时会发现 <code>centos7</code> 目录下已经创建了一个 <code>Vagrantfile</code>，里面已经包含了默认的配置。</p>
<h3 id="43-安装-启动">4.3. 安装 / 启动</h3>
<p>在 Terminal 中输入如下命令，即可进行自动安装虚拟机：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ vagrant up</span><br></pre></td></tr></table></figure>
<p>等待几分钟，即可安装成功。</p>
<h3 id="44-登录">4.4. 登录</h3>
<p>在 Terminal 中执行如下命令：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ vagrant ssh</span><br></pre></td></tr></table></figure>
<p>就会登录到虚拟机的 bash 中，非常方便。</p>
<blockquote>
<p>这里需要注意，windows用户直接使用cmd命令不能使用ssh，建议使用 git-bash.exe 进行操作</p>
</blockquote>
<hr>
<h2 id="5-vagrant-高阶操作">5. Vagrant 高阶操作</h2>
<h3 id="51-共享宿主机文件夹">5.1. 共享宿主机文件夹</h3>
<p>实现共享文件夹，首先我们必须先安装一个 Vagrant 插件：<code>vagrant-vbguest</code>，打开 Terminal 输入以下命令安装：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ vagrant plugin install vagrant-vbguest</span><br><span class="line">Installing the &#39;vagrant-vbguest&#39; plugin. This can take a few minutes...</span><br><span class="line">Fetching: micromachine-2.0.0.gem (100%)</span><br><span class="line">Fetching: vagrant-vbguest-0.17.2.gem (100%)</span><br><span class="line">Installed the plugin &#39;vagrant-vbguest (0.17.2)&#39;!</span><br></pre></td></tr></table></figure>
<p>安装成功后，我们只需要在 <code>Vagrantfile</code> 中配置共享文件夹，参考如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"># 第一个参数是宿主机文件夹地址</span><br><span class="line"># 第二个参数是虚拟机中映射过去的虚拟文件夹地址</span><br><span class="line">config.vm.synced_folder &quot;..&#x2F;data&quot;, &quot;&#x2F;vagrant_data&quot;</span><br></pre></td></tr></table></figure>
<h3 id="52-网络代理配置">5.2. 网络代理配置</h3>
<p>这里我们总共有 3 个步骤实现网络代理：</p>
<h4 id="521-安装插件">5.2.1. 安装插件</h4>
<p>实现网络代理，首先我们必须先安装一个 Vagrant 插件：<code>vagrant-proxyconf</code>，打开 Terminal 输入以下命令安装：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ vagrant plugin install vagrant-proxyconf</span><br><span class="line">Installing the &#39;vagrant-proxyconf&#39; plugin. This can take a few minutes...</span><br><span class="line">Fetching: vagrant-proxyconf-2.0.1.gem (100%)</span><br><span class="line">Installed the plugin &#39;vagrant-proxyconf (2.0.1)&#39;!</span><br></pre></td></tr></table></figure>
<h4 id="522-配置宿主机固定-ip">5.2.2. 配置宿主机固定 IP</h4>
<p>注意：这里我们是对 VirtualBox 全局设置，前往不要仅对某一台虚拟机设置了，这样的好处是所有的虚拟机都会绑定上我们配置的网卡信息。</p>
<p>安装成功后，我们还需要拿到宿主机的一个固定 IP，显然这个 IP 需要在我们切换网络环境的时候，仍然保证固定不变。此时我们可以通过 <code>VirtualBox</code> 自带的一个小技巧实现~</p>
<p>打开 VirtualBox，找到左上角 『工具』右侧的小图标，点击该图标，选择『网络』，可以看到如下界面：</p>
<p><a href="https://camo.githubusercontent.com/a2bba3dba8a473d5f28dacf0a1bf6002ce24a6c1dec700623574b6f685fefba1/68747470733a2f2f7374617469632e786b636f64696e672e636f6d2f626c6f672f7573652d76616772616e742d6275696c642d6c696e75782d7669727475616c2d6d616368696e652f696d6167652d7669727475616c626f782d73657475702d657468302e706e67" target="_blank" rel="noopener"><img src="https://camo.githubusercontent.com/a2bba3dba8a473d5f28dacf0a1bf6002ce24a6c1dec700623574b6f685fefba1/68747470733a2f2f7374617469632e786b636f64696e672e636f6d2f626c6f672f7573652d76616772616e742d6275696c642d6c696e75782d7669727475616c2d6d616368696e652f696d6167652d7669727475616c626f782d73657475702d657468302e706e67" alt="VirtualBox配置网卡信息"></a></p>
<p>可以看到网卡列表里存在网卡信息，如果不存在，可以自己手动创建。这里网卡信息里的必须选择『手动配置网卡』。我们可以从虚拟机中访问宿主机的固定IP就是这里的IPv4地址。</p>
<h4 id="523-配置-vagrantfile">5.2.3. 配置 <code>Vagrantfile</code></h4>
<p>最后，我们需要在 <code>Vagrantfile</code> 中配置代理，参考如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">if Vagrant.has_plugin?(&quot;vagrant-proxyconf&quot;)</span><br><span class="line">  config.proxy.http     &#x3D; &quot;http:&#x2F;&#x2F;192.168.205.1:1087&#x2F;&quot;</span><br><span class="line">  config.proxy.https    &#x3D; &quot;http:&#x2F;&#x2F;192.168.205.1:1087&#x2F;&quot;</span><br><span class="line">  config.proxy.no_proxy &#x3D; &quot;localhost,127.0.0.1&quot;</span><br><span class="line">end</span><br></pre></td></tr></table></figure>
<p>这样启动虚拟机之后，我们的网络请求都会通过我们宿主机的 1087 端口代理出去。</p>
<h3 id="53-安装后系统环境配置">5.3. 安装后系统环境配置</h3>
<p>Vagrant 可以在虚拟机安装之后，使用 shell 命令对系统环境做一些初始化配置，我们可以在 <code>Vagrantfile</code> 中配置。</p>
<p>Vagrant 支持 2 种方式执行 shell，第一种方式是直接在 Vagrantfile 中写 shell 命令，如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">config.vm.provision &quot;shell&quot;, privileged: true, inline: &lt;&lt;-SHELL</span><br><span class="line">	apt-get update</span><br><span class="line">	apt-get install -y apache2</span><br><span class="line">SHELL</span><br></pre></td></tr></table></figure>
<p>第二种方式，支持引用外部 shell 脚本，如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">config.vm.provision &quot;shell&quot;, privileged: true, path: &quot;.&#x2F;setup.sh&quot;</span><br></pre></td></tr></table></figure>
<h3 id="54-如何配置聚群化环境">5.4. 如何配置聚群化环境</h3>
<h4 id="541-设置硬件参数">5.4.1. 设置硬件参数</h4>
<p>设置虚拟机内存大小和CPU核数，在 <code>Vagrantfile</code> 中配置如下信息即可：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">config.vm.provider &quot;virtualbox&quot; do |v|</span><br><span class="line">  v.customize [&quot;modifyvm&quot;, :id, &quot;--memory&quot;, &quot;1024&quot;]</span><br><span class="line">  v.customize [&quot;modifyvm&quot;, :id, &quot;--cpus&quot;, &quot;1&quot;]</span><br><span class="line">end</span><br></pre></td></tr></table></figure>
<h4 id="542-设置hostname">5.4.2. 设置hostname</h4>
<p>在 <code>Vagrantfile</code> 中配置如下信息即可：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">config.vm.hostname &#x3D; &quot;master1&quot;</span><br></pre></td></tr></table></figure>
<h4 id="543-设置静态ip">5.4.3. 设置静态IP</h4>
<p>在 <code>Vagrantfile</code> 中配置如下信息即可：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">config.vm.network &quot;private_network&quot;, ip: &quot;192.168.205.10&quot;</span><br></pre></td></tr></table></figure>
<h3 id="55-可用插件">5.5. 可用插件</h3>
<p>从上面的 <em><code>共享宿主机文件夹</code></em>、<em><code>网络代理</code></em> 等高阶操作，我们可以发现，Vagrant 拥有丰富的插件可以帮助我们完成很多个性化需求，对于这些插件，官方提供了一个地址，专门整理了大量的 Vagrant 插件。</p>
<blockquote>
<p>插件列表地址：<a href="https://github.com/hashicorp/vagrant/wiki/Available-Vagrant-Plugins" target="_blank" rel="noopener">https://github.com/hashicorp/vagrant/wiki/Available-Vagrant-Plugins</a></p>
</blockquote>
<hr>
<h2 id="6-vagrantfile-案例">6. Vagrantfile 案例</h2>
<blockquote>
<p>本小节，我们展示一个 <code>Vagrantfile</code> 启动 3 台虚拟机节点，设置好硬件信息、安装docker、并设置开机启动，同时开启代理配置。</p>
</blockquote>
<p><strong>Vagrantfile</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line"># -*- mode: ruby -*-</span><br><span class="line"># vi: set ft&#x3D;ruby :</span><br><span class="line"></span><br><span class="line"># 设置虚拟机配置，包括hostname，ip，内存，CPU等</span><br><span class="line">boxes &#x3D; [</span><br><span class="line">    &#123;</span><br><span class="line">        :name &#x3D;&gt; &quot;master1&quot;,</span><br><span class="line">        :eth1 &#x3D;&gt; &quot;192.168.205.10&quot;,</span><br><span class="line">        :mem &#x3D;&gt; &quot;1024&quot;,</span><br><span class="line">        :cpu &#x3D;&gt; &quot;1&quot;</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">        :name &#x3D;&gt; &quot;slave1&quot;,</span><br><span class="line">        :eth1 &#x3D;&gt; &quot;192.168.205.11&quot;,</span><br><span class="line">        :mem &#x3D;&gt; &quot;1024&quot;,</span><br><span class="line">        :cpu &#x3D;&gt; &quot;1&quot;</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">        :name &#x3D;&gt; &quot;slave2&quot;,</span><br><span class="line">        :eth1 &#x3D;&gt; &quot;192.168.205.12&quot;,</span><br><span class="line">        :mem &#x3D;&gt; &quot;1024&quot;,</span><br><span class="line">        :cpu &#x3D;&gt; &quot;1&quot;</span><br><span class="line">    &#125;</span><br><span class="line">]</span><br><span class="line"></span><br><span class="line">Vagrant.configure(&quot;2&quot;) do |config|</span><br><span class="line">  # box名称</span><br><span class="line">  config.vm.box &#x3D; &quot;centos&#x2F;7&quot;</span><br><span class="line"></span><br><span class="line">  # 循环设置每台虚拟机</span><br><span class="line">  boxes.each do |opts|</span><br><span class="line">    config.vm.define opts[:name] do |config|</span><br><span class="line">      # 配置 hostname</span><br><span class="line">      config.vm.hostname &#x3D; opts[:name]</span><br><span class="line"></span><br><span class="line">      # 配置内存和CPU</span><br><span class="line">      config.vm.provider &quot;virtualbox&quot; do |v|</span><br><span class="line">        v.customize [&quot;modifyvm&quot;, :id, &quot;--memory&quot;, opts[:mem]]</span><br><span class="line">        v.customize [&quot;modifyvm&quot;, :id, &quot;--cpus&quot;, opts[:cpu]]</span><br><span class="line">      end</span><br><span class="line"></span><br><span class="line">      # 配置 IP</span><br><span class="line">      config.vm.network :private_network, ip: opts[:eth1]</span><br><span class="line">      </span><br><span class="line">      # 设置网络代理(需要安装 vagrant-proxyconf 插件)</span><br><span class="line">      if Vagrant.has_plugin?(&quot;vagrant-proxyconf&quot;)</span><br><span class="line">        config.proxy.http     &#x3D; &quot;http:&#x2F;&#x2F;192.168.205.1:1087&#x2F;&quot;</span><br><span class="line">        config.proxy.https    &#x3D; &quot;http:&#x2F;&#x2F;192.168.205.1:1087&#x2F;&quot;</span><br><span class="line">        config.proxy.no_proxy &#x3D; &quot;localhost,127.0.0.1&quot;</span><br><span class="line">      end</span><br><span class="line"></span><br><span class="line">      # 设置启动后初始化脚本，注意 privileged: true，表示以 sudo 方式运行</span><br><span class="line">      config.vm.provision &quot;shell&quot;, privileged: true, path: &quot;.&#x2F;setup.sh&quot;</span><br><span class="line">      </span><br><span class="line">      # 设置宿主机共享文件夹(需要安装 vagrant-vbguest 插件)</span><br><span class="line">      # config.vm.synced_folder &quot;..&#x2F;data&quot;, &quot;&#x2F;vagrant_data&quot;</span><br><span class="line">    end</span><br><span class="line">  end</span><br><span class="line"></span><br><span class="line">end</span><br></pre></td></tr></table></figure>
<p><strong><a href="http://setup.sh" target="_blank" rel="noopener">setup.sh</a></strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">#&#x2F;bin&#x2F;sh</span><br><span class="line"></span><br><span class="line"># set timezone</span><br><span class="line">echo &quot;set timezone&quot;</span><br><span class="line">timedatectl set-timezone Asia&#x2F;Shanghai</span><br><span class="line"></span><br><span class="line">echo &quot;vagrant ALL&#x3D;(ALL) NOPASSWD: ALL&quot; &gt;&gt; &#x2F;etc&#x2F;sudoers</span><br><span class="line"></span><br><span class="line"># change yum repo</span><br><span class="line">echo &quot;change yum repo -&gt; aliyun repo&quot;</span><br><span class="line">sudo yum install -y wget yum-utils</span><br><span class="line">sudo cp &#x2F;etc&#x2F;yum.repos.d&#x2F;CentOS-Base.repo &#x2F;etc&#x2F;yum.repos.d&#x2F;CentOS-Base.repo.bak</span><br><span class="line">sudo wget -O &#x2F;etc&#x2F;yum.repos.d&#x2F;CentOS-Base.repo http:&#x2F;&#x2F;mirrors.aliyun.com&#x2F;repo&#x2F;Centos-7.repo</span><br><span class="line">sudo wget -P &#x2F;etc&#x2F;yum.repos.d&#x2F; http:&#x2F;&#x2F;mirrors.aliyun.com&#x2F;repo&#x2F;epel-7.repo </span><br><span class="line">sudo yum clean all</span><br><span class="line">sudo yum makecache</span><br><span class="line"></span><br><span class="line"># install some tools</span><br><span class="line">echo &quot;install some tools&quot;</span><br><span class="line">sudo yum install -y yum-utils device-mapper-persistent-data lvm2 git vim gcc glibc-static telnet bridge-utils</span><br><span class="line"></span><br><span class="line"># install docker</span><br><span class="line">echo &quot;install docker&quot;</span><br><span class="line">sudo yum-config-manager --add-repo http:&#x2F;&#x2F;mirrors.aliyun.com&#x2F;docker-ce&#x2F;linux&#x2F;centos&#x2F;docker-ce.repo</span><br><span class="line">sudo yum makecache fast</span><br><span class="line">sudo yum -y install docker-ce</span><br><span class="line"></span><br><span class="line"># start docker service</span><br><span class="line">echo &quot;start docker service&quot;</span><br><span class="line">sudo groupadd docker</span><br><span class="line">sudo usermod -aG docker vagrant</span><br><span class="line">sudo systemctl enable docker</span><br></pre></td></tr></table></figure>

                

                <hr>
                <!-- Pager -->
                <ul class="pager">
                    
                        <li class="previous">
                            <a href="/插件/2019-01-11/" data-toggle="tooltip" data-placement="top" title="Eclipse+JRebel+Tomcat热部署">&larr; Previous Post</a>
                        </li>
                    
                    
                        <li class="next">
                            <a href="/Mac/2019-01-03/" data-toggle="tooltip" data-placement="top" title="Mac 下 Homebrew 常用命令">Next Post &rarr;</a>
                        </li>
                    
                </ul>

                <br>

                <!--打赏-->
                
                <!--打赏-->

                <br>
                <!--分享-->
                
                    <div class="social-share"  data-wechat-qrcode-helper="" align="center"></div>
                    <!--  css & js -->
                    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/css/share.min.css">
                    <script src="https://cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/js/social-share.min.js"></script>
                
                <!--分享-->
                <br>                       
                
                <!-- require APlayer -->
                

                <!-- duoshuo Share start -->
                
                <!-- 多说 Share end-->

                <!-- 多说评论框 start -->
                
                <!-- 多说评论框 end -->

                <!-- disqus comment start -->
                
                    <div class="comment">
                        <div id="disqus_thread" class="disqus-thread"></div>
                    </div>
                
                <!-- disqus comment end -->

                

            </div>
            
            <!-- Tabe of Content -->
            <!-- Table of Contents -->

  
    <style>
      span.toc-nav-number{
        display: none
      }
    </style>
  
    
      <aside id="sidebar">
        <div id="toc" class="toc-article">
        <strong class="toc-title">Contents</strong>
        
          <ol class="toc-nav"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#前言"><span class="toc-nav-number">1.</span> <span class="toc-nav-text">前言</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#1-什么是-vagrant"><span class="toc-nav-number">2.</span> <span class="toc-nav-text">1. 什么是 Vagrant</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#11-vagrant-简介"><span class="toc-nav-number">2.1.</span> <span class="toc-nav-text">1.1. Vagrant 简介</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#12-vagrant-优势"><span class="toc-nav-number">2.2.</span> <span class="toc-nav-text">1.2. Vagrant 优势</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#2-安装-vagrant"><span class="toc-nav-number">3.</span> <span class="toc-nav-text">2. 安装 Vagrant</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#21-环境准备"><span class="toc-nav-number">3.1.</span> <span class="toc-nav-text">2.1. 环境准备</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#22-安装-vagrant"><span class="toc-nav-number">3.2.</span> <span class="toc-nav-text">2.2. 安装 Vagrant</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#3-vagrant-命令"><span class="toc-nav-number">4.</span> <span class="toc-nav-text">3. Vagrant 命令</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#4-vagrant-实战"><span class="toc-nav-number">5.</span> <span class="toc-nav-text">4. Vagrant 实战</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#41-寻找box"><span class="toc-nav-number">5.1.</span> <span class="toc-nav-text">4.1. 寻找box</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#42-初始化"><span class="toc-nav-number">5.2.</span> <span class="toc-nav-text">4.2. 初始化</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#43-安装-启动"><span class="toc-nav-number">5.3.</span> <span class="toc-nav-text">4.3. 安装 &#x2F; 启动</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#44-登录"><span class="toc-nav-number">5.4.</span> <span class="toc-nav-text">4.4. 登录</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#5-vagrant-高阶操作"><span class="toc-nav-number">6.</span> <span class="toc-nav-text">5. Vagrant 高阶操作</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#51-共享宿主机文件夹"><span class="toc-nav-number">6.1.</span> <span class="toc-nav-text">5.1. 共享宿主机文件夹</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#52-网络代理配置"><span class="toc-nav-number">6.2.</span> <span class="toc-nav-text">5.2. 网络代理配置</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#521-安装插件"><span class="toc-nav-number">6.2.1.</span> <span class="toc-nav-text">5.2.1. 安装插件</span></a></li><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#522-配置宿主机固定-ip"><span class="toc-nav-number">6.2.2.</span> <span class="toc-nav-text">5.2.2. 配置宿主机固定 IP</span></a></li><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#523-配置-vagrantfile"><span class="toc-nav-number">6.2.3.</span> <span class="toc-nav-text">5.2.3. 配置 Vagrantfile</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#53-安装后系统环境配置"><span class="toc-nav-number">6.3.</span> <span class="toc-nav-text">5.3. 安装后系统环境配置</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#54-如何配置聚群化环境"><span class="toc-nav-number">6.4.</span> <span class="toc-nav-text">5.4. 如何配置聚群化环境</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#541-设置硬件参数"><span class="toc-nav-number">6.4.1.</span> <span class="toc-nav-text">5.4.1. 设置硬件参数</span></a></li><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#542-设置hostname"><span class="toc-nav-number">6.4.2.</span> <span class="toc-nav-text">5.4.2. 设置hostname</span></a></li><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#543-设置静态ip"><span class="toc-nav-number">6.4.3.</span> <span class="toc-nav-text">5.4.3. 设置静态IP</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#55-可用插件"><span class="toc-nav-number">6.5.</span> <span class="toc-nav-text">5.5. 可用插件</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#6-vagrantfile-案例"><span class="toc-nav-number">7.</span> <span class="toc-nav-text">6. Vagrantfile 案例</span></a></li></ol>
        
        </div>
      </aside>
    

                
            <!-- Sidebar Container -->
            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                sidebar-container">

                <!-- Featured Tags -->
                
                <section>
                    <!-- no hr -->
                    <h5><a href="/tags/">FEATURED TAGS</a></h5>
                    <div class="tags">
                       
                          <a class="tag" href="/tags/#工具" title="工具">工具</a>
                        
                    </div>
                </section>
                

                <!-- Friends Blog -->
                
            </div>
        </div>
    </div>
</article>




<!-- disqus embedded js code start (one page only need to embed once) -->
<script type="text/javascript">
    /* * * CONFIGURATION VARIABLES * * */
    var disqus_shortname = "your-disqus-ID";
    var disqus_identifier = "http://www.wangxiaohuan.com/%E8%99%9A%E6%8B%9F%E6%9C%BA/2019-01-07/";
    var disqus_url = "http://www.wangxiaohuan.com/%E8%99%9A%E6%8B%9F%E6%9C%BA/2019-01-07/";

    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>
<!-- disqus embedded js code start end -->





<!-- async load function -->
<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>
<!-- anchor-js, Doc:http://bryanbraun.github.io/anchorjs/ -->
<script>
    async("https://cdn.bootcss.com/anchor-js/1.1.1/anchor.min.js",function(){
        anchors.options = {
          visible: 'hover',
          placement: 'left',
          icon: 'ℬ'
        };
        anchors.add().remove('.intro-header h1').remove('.subheading').remove('.sidebar-container h5');
    })
</script>
<style>
    /* place left on bigger screen */
    @media all and (min-width: 800px) {
        .anchorjs-link{
            position: absolute;
            left: -0.75em;
            font-size: 1.1em;
            margin-top : -0.1em;
        }
    }
</style>



    <!-- Footer -->
    <!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <ul class="list-inline text-center">
                
                
                    <li>
                        <a target="_blank" href="https://twitter.com/work_wxh">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-twitter fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
                
                

                
                    <li>
                        <a target="_blank" href="http://weibo.com/2742646782">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-weibo fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
                

                
                    <li>
                        <a target="_blank" href="https://www.facebook.com/wxh.work">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-facebook fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
                

                
                    <li>
                        <a target="_blank"  href="https://github.com/xiaohuanwang">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
                

                

                </ul>
                <p class="copyright text-muted">
                    Copyright &copy; 吃素的左撇子 2022 
                    <br>
                    Theme by <a href="http://beantech.org" target="_blank" rel="noopener">BeanTech</a> 
                    <span style="display: inline-block; margin: 0 5px;">
                        <i class="fa fa-heart"></i>
                    </span> 
                    re-Ported by <a href="http://www.wangxiaohuan.com">吃素的左撇子</a> | 
                    <iframe
                        style="margin-left: 2px; margin-bottom:-5px;"
                        frameborder="0" scrolling="0" width="91px" height="20px"
                        src="https://ghbtns.com/github-btn.html?user=xiaohuanwang&repo=hexo-theme-xiaohuanwang&type=star&count=true" >
                    </iframe>
                </p>
            </div>
        </div>
    </div>
</footer>

<!-- jQuery -->

<script src="/js/jquery.min.js"></script>


<!-- Bootstrap Core JavaScript -->

<script src="/js/bootstrap.min.js"></script>


<!-- Custom Theme JavaScript -->

<script src="/js/hux-blog.min.js"></script>



<!-- async load function -->
<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>

<!-- 
     Because of the native support for backtick-style fenced code blocks 
     right within the Markdown is landed in Github Pages, 
     From V1.6, There is no need for Highlight.js, 
     so Huxblog drops it officially.

     - https://github.com/blog/2100-github-pages-now-faster-and-simpler-with-jekyll-3-0  
     - https://help.github.com/articles/creating-and-highlighting-code-blocks/    
-->
<!--
    <script>
        async("http://cdn.bootcss.com/highlight.js/8.6/highlight.min.js", function(){
            hljs.initHighlightingOnLoad();
        })
    </script>
    <link href="http://cdn.bootcss.com/highlight.js/8.6/styles/github.min.css" rel="stylesheet">
-->


<!-- jquery.tagcloud.js -->
<script>
    // only load tagcloud.js in tag.html
    if($('#tag_cloud').length !== 0){
        async("http://www.wangxiaohuan.com/js/jquery.tagcloud.js",function(){
            $.fn.tagcloud.defaults = {
                //size: {start: 1, end: 1, unit: 'em'},
                color: {start: '#bbbbee', end: '#0085a1'},
            };
            $('#tag_cloud a').tagcloud();
        })
    }
</script>

<!--fastClick.js -->
<script>
    async("https://cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js", function(){
        var $nav = document.querySelector("nav");
        if($nav) FastClick.attach($nav);
    })
</script>


<!-- Google Analytics -->


<script>
    // dynamic User by Hux
    var _gaId = 'UA-XXXXXXXX-X';
    var _gaDomain = 'yoursite';

    // Originial
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', _gaId, _gaDomain);
    ga('send', 'pageview');
</script>




<!-- Baidu Tongji -->

<script>
    // dynamic User by Hux
    var _baId = 'xxx';

    // Originial
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?" + _baId;
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
</script>






	<a id="rocket" href="#top" class=""></a>
	<script type="text/javascript" src="/js/totop.js?v=1.0.0" async=""></script>
    <script type="text/javascript" src="/js/toc.js?v=1.0.0" async=""></script>
<!-- Image to hack wechat -->
<img src="http://www.wangxiaohuan.com/img/icon_wechat.png" width="0" height="0" />
<!-- Migrate from head to bottom, no longer block render and still work -->

</body>

</html>
